StopCondition

fun interface StopCondition

First-class loop stop conditions (invariant I-7). The SDK manages the loop; consumers express completion as a StopCondition passed to the agent constructor or generateText.

Built-ins:

  • stepCountIs — stop after N completed steps. Default stepCountIs(20) so any agent without explicit stopWhen still terminates.

  • hasToolCall — stop the moment a specific tool is called.

  • anyOf — short-circuit OR over multiple conditions (matches v6's array form).

Custom: implement StopCondition directly. Receives a snapshot of the loop state on every check.

Functions

Link copied to clipboard
abstract suspend fun shouldStop(state: LoopState): Boolean

True if the loop should stop after the just-completed step.